<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <title>主用户管理</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
    <style type="text/css">
    	span.required {
    		color: red;
    		margin-right: 6px;
    	}
    	div.box-body {
    		margin-top:7px;
    	}
    </style>
</head>
<body class="skin-blue sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>${(opType==0)?"主用户管理新增":"主用户管理编辑"}</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="${ctx }/sysRole/zxRoleList.html">主用户管理</a></li>
            <li class="active"><a href="#">${(opType==0)?"主用户管理新增":"主用户管理编辑"}</a></li>
        </ol>
    </section>
    <section class="content">
    <form id="form" class="form-horizontal" action="zxSaveUser.html" method="post">
            	<input type="hidden" name="id" value="${user.id}" />
            	<input type="hidden" name="opType" value="${opType}" />
            	<input type="hidden" name="locked" value="0" />
            	<input type="hidden" id="privileges" name="privileges" />
            	<input type="hidden" name="type" value="${user.type}" />
        <div class=" box box-success ">
           <div class="box-body" >
                    <div class="form-group form-group-xs">
                        <label for="username" class="col-sm-2 text-right"><span class="required">*</span>用户帐号：</label>
                        <div class="col-sm-3 text-left">
                            <input class="form-control" id="username" name="username" value="${user.username}" placeholder="用户帐号" type="text" readonly="readonly">
                        </div>
                        <label for="name" class="col-sm-3 text-right"><span class="required">*</span>用户名称：</label>
                        <div class="col-sm-3 text-left">
                            <input class="form-control" id="name" name="name" value="${user.name}" placeholder="用户名称" type="text" >
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="email" class="col-sm-2 text-right">邮箱：</label>
                        <div class="col-sm-3 text-left">
                            <input class="form-control" id="email" name="email" value="${user.email}" placeholder="用户邮箱" type="text" >
                        </div>
                        <label for="phone" class="col-sm-3 text-right">联系电话：</label>
                        <div class="col-sm-3 text-left">
                            <input class="form-control" id="phone" name="phone" value="${user.phone}" placeholder="联系电话" type="text" maxlength="20">
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="remark" class="col-sm-2 control-label">备注：</label>
                        <div class="col-sm-9">
                            <textarea class="form-control" id="remark" name="remark" rows="3" placeholder="备注" maxlength="500">${user.remark}</textarea>
                        </div>
                    </div>
                </div>
                <div class="box-footer text-center">
                    <button type="button" class="btn btn-success btn-sm" onclick="zxSaveUser();">保&nbsp;存</button>
                    <a href="${ctx}/sysUser/zxUserList.html" class="btn btn-danger btn-sm">返&nbsp;回</a>
                </div>   
           </div>
        </form>
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    
    <script type="text/javascript">
    	var treeObj = null;
    
    	//	获取选中的权限
    	function getCheckedPrivilege() {
    		if (treeObj != null) {
    			var nodes = treeObj.getCheckedNodes(true) || [];
    			if (nodes.length > 0) {
    				var params = [];
    				for (var i=0; i<nodes.length; i++) {
        				var node = nodes[i] || {};
        				params.push({"id":node.id});
        			}
    				$("#privileges").val(json.jsonToString(params));
    			}
    		}
    	}
    
    	//	保存用户信息
    	function zxSaveUser() {
    		if (!validate()) {
    			return;
    		}
    		getCheckedPrivilege();
    		$("#form").ajaxSubmit({
    			dataType : "json",
    			timeout: 10000,
    			success : function(result, statusText) {
    				if (result.success) {
    					if ("${opType}" == "0") {
    						document.location = "${ctx}/sysUser/printUserInfo.html?id=${user.id}";
    					} else {
    						$.HN.message.alert("保存成功！", "消息", "success", function() {
    							document.location = "${ctx}/sysUser/zxUserList.html";
        					});
    					}
    				} else {
    					$.HN.message.alert(result.msg || "", "消息", "error");
    				}
    			}
    		});
    	}
    	
    	//	校验用户信息
    	function validate() {
    		var name = $.trim($("#name").val());
    		if (name == null || name == "") {
    			$.HN.message.alert("请输入用户名称！", "消息", "warn");
    			$("#name").focus();
    			return false;
    		}
    		
    		var email = $.trim($("#email").val());
    		if (email.replace(/(^s*)|(s*$)/g, "").length !=0) {
    			 var a =/[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/;
    			if(!a.test(email)){
		        	$.HN.message.alert("电子邮箱格式不正确！", "消息", "warn");
		        	$("#email").focus();
	    			return false;
		   		 }
    		}
    		var phone = $.trim($("#phone").val());
    		if (phone.replace(/(^s*)|(s*$)/g, "").length !=0) {
    			var b=/((15)\d{9})|((13)\d{9})|((18)\d{9})|(0[1-9]{2,3}\-?[1-9]{6,7})/i;  
    			if(!b.test(phone)){
    		        	$.HN.message.alert("请输入正确的电话号码，\n\n如：0591-6487256，15005059587", "消息", "warn");
    		        	$("#phone").focus();
    	    			return false;
    		    }
    		}
    		return true;
    	}
    
    	$(document).ready(function() {
    		
    	});
    </script>
    
</body>
</html>
